#!/usr/bin/env perl

use utf8;
use strict;

sub total{
	my($sum);
	foreach(@_){
		$sum += $_;
	}
	return $sum;
}

sub average{
	my $ave;

	$ave = &total(@_) / ($#_ + 1);

	return $ave;
}

sub above_average{
	my($ave, $cur, @above);

	$ave = &average(@_);

	print "average --> $ave\n";

	while($cur = pop @_){
		if($cur > $ave){
			push @above, $cur;
		}
	}

	return @above;
}

my @fred = &above_average(1..10);

print "\@fred is @fred.\n";
print "(Should be 6 7 8 9 10)\n";

my @barney = &above_average(100, 1..10);

print "\@barney is @barney.\n";
print "(Should be just 100)\n";
